package com.szsfm.vehiclemanagement.activity;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.bumptech.glide.Glide;
import com.szsfm.vehiclemanagement.R;
import com.szsfm.vehiclemanagement.base.BaseActivity;

import uk.co.senab.photoview.PhotoView;

public class PhotoViewActivity extends BaseActivity implements View.OnClickListener {

    private PhotoView mPhotoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo_view);
        Uri uri=null;
        String path=null;
        if (getIntent().hasExtra("uri")) uri = getIntent().getParcelableExtra("uri");
        if (getIntent().hasExtra("path")) path = getIntent().getStringExtra("path");

        mPhotoView = (PhotoView) findViewById(R.id.photo_view);
        if (uri != null) {
            Glide.with(this).load(uri).into(mPhotoView);
        }else {
            Glide.with(this).load(path).into(mPhotoView);
        }

        mPhotoView.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        finish();
    }

    public static void startSelf(Context context, Uri uri) {
        Intent intent = new Intent(context, PhotoViewActivity.class);
        intent.putExtra("uri", uri);
        context.startActivity(intent);
    }

    public static void startSelf(Context context, String uri) {
        Intent intent = new Intent(context, PhotoViewActivity.class);
        intent.putExtra("path", uri);
        context.startActivity(intent);
    }

}
